package com.graduation.springbootinit.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.graduation.springbootinit.mapper.PointsRecordMapper;
import com.graduation.springbootinit.model.entity.ActivityPart.PointsRecord;
import com.graduation.springbootinit.service.PointsRecordService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PointsRecordServiceImpl extends ServiceImpl<PointsRecordMapper, PointsRecord>
        implements PointsRecordService {

    @Override
    public Page<PointsRecord> getUserPointsRecords(Long userId, int pageNum, int pageSize) {
        Page<PointsRecord> page = new Page<>(pageNum, pageSize);
        return baseMapper.selectPageByUserId(page, userId);
    }

    @Override
    public List<PointsRecord> getRecentPointsRecords(Long userId, int limit) {
        return baseMapper.selectRecentByUserId(userId, limit);
    }

    @Override
    public void createPointsRecord(Long userId, Integer points, Integer type, String description) {
        PointsRecord record = new PointsRecord();
        record.setUserId(userId);
        record.setPoints(points);
        record.setType(type);
        record.setDescription(description);
        save(record);
    }
} 